package org.rcy.framework.data.datasource;

import java.util.Locale;

public enum Database {

	/**
	 * MySQL.
	 */
	MYSQL("MySQL", "com.mysql.cj.jdbc.Driver","jdbc:mysql://{}:{}/{}?serverTimezone=GMT%2B8&useUnicode=true&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true","`{0}`"),

	/**
	 * Oracle.
	 */
	//ORACLE("Oracle", "oracle.jdbc.OracleDriver", "jdbc:oracle:thin:@{}:{}:{}"),
	ORACLE("Oracle", "oracle.jdbc.OracleDriver", "jdbc:oracle:thin:@//{}:{}/{}","\"LEVEL\""),

	/**
	 * SQL Server.
	 */
	SQLSERVER("Microsoft SQL Server", "com.microsoft.sqlserver.jdbc.SQLServerDriver","jdbc:sqlserver://{}:{};DatabaseName={}","[{0}]"),
	/**
	 * DM Server
	 */
	DM("DM DBMS", "dm.jdbc.driver.DmDriver","jdbc:dm://{}:{}","{0}"),

	/**
	 *  神通
	 */
	OSCAR("OSCAR", "com.oscar.Driver","jdbc:oscar://{}:{}/{}","{0}"),

	/**
	 *  人大金仓
	 */
	KINGBASEES("KingbaseES", "com.kingbase8.Driver","jdbc:kingbase8://{}:{}/{}","{0}"),

	/**
	 *  openGauss
	 */
	POSTGRESQL("PostgreSQL", "org.postgresql.Driver","jdbc:postgresql://{}:{}/{}","{0}");

	private final String productName;
	private final String driverClassName;
	private final String jdbcUrl;
	private final String keywordWrap;

	private Database(String productName, String driverClassName, String jdbcUrl,String keywordWrap) {
		this.productName = productName;
		this.driverClassName = driverClassName;
		this.jdbcUrl = jdbcUrl;
		this.keywordWrap = keywordWrap;
	}

	public String databaseId() {
		return name().toLowerCase(Locale.ENGLISH);
	}

	public String productName() {
		return productName;
	}

	public String driverClassName() {
		return driverClassName;
	}

	public String jdbcUrl() {
		return jdbcUrl;
	}
	
	
	public String keywordWrap() {
		return keywordWrap;
	}

	/**
	 * 根据databaseId 获取对应的Database对象
	 * @param databaseId
	 * @return 返回对应的Database，如果没有匹配则返回null
	 */
	public static Database fromDatabaseId(String databaseId) {
		for(Database db:Database.values()) {
			if(db.databaseId().equals(databaseId)) {
				return db;
			}
		}
		return null;
	}
	
	/**
	 * 获取关键字处理策略
	 * @param databaseId
	 * @return
	 */
	public static String getkeywordWrap(String databaseId) {
		for(Database db:Database.values()) {
			if(db.databaseId().equals(databaseId)) {
				return db.keywordWrap();
			}
		}
		return "{0}";
	}
}
